package com.wjj.sixinone.controller.admin;


import com.wjj.sixinone.common.enums.ApiTypeConst;
import com.wjj.sixinone.common.pojo.vo.DrugFormVO;
import com.wjj.sixinone.common.pojo.vo.DrugVO;
import com.wjj.sixinone.common.util.Result;
import com.wjj.sixinone.service.DrugService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 小王不秃头
 * @since 2024-07-22
 */
@RestController
@RequestMapping(ApiTypeConst.API_ADMIN+"/drug")
public class DrugController {
    @Autowired
    private DrugService drugService;
    @GetMapping("/selectDrugByLimit")
    public Result selectDrugByLimit( DrugVO drugVO){

        return drugService.selectDrugByLimit(drugVO);
    }
    @GetMapping("/uploadExcel")
    public void uploadExcel(HttpServletResponse response) {
         drugService.uploadExcel(response);

    }
    @PostMapping("/deleteById")
    public Result deleteById(@RequestBody Map<String,String> map){
        String id = map.get("id");
        String img = map.get("img");

        return drugService.removeDrugById(id,img);
    }
    @PostMapping("/updateById")
    public Result updateById(@RequestBody DrugFormVO drugFormVO){
        return drugService.updateDrugById(drugFormVO);
    }

    @PostMapping("/addDrug")
    public Result addDrug(@RequestBody DrugFormVO drugFormVO){
        return drugService.addDrug(drugFormVO);
    }
}

